#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution1 {
    const int mod = 1e9 + 7;
public:
    int maxArea(int h, int w, vector<int>& horizontalCuts, vector<int>& verticalCuts) {
        sort(horizontalCuts.begin(), horizontalCuts.end());
        sort(verticalCuts.begin(), verticalCuts.end());

        int h_nums = horizontalCuts.size(), v_nums = verticalCuts.size();
        int max_brock = (horizontalCuts[0] * verticalCuts[0]) % mod;
        for (int i = 1; i <= v_nums; i++)
        {
            int tmp = 0;
            if (i == v_nums)
            {
                tmp = (horizontalCuts[0] * (w - verticalCuts[i - 1])) % mod;
            }
            else
            {
                tmp = (horizontalCuts[0] * (verticalCuts[i] - verticalCuts[i - 1])) % mod;
            }

            max_brock = max(tmp, max_brock);
        }
        for (int j = 1; j < h_nums; j++)
        {
            for (int i = 0; i <= v_nums; i++)
            {
                int tmp = 0;
                if (i == v_nums)
                {
                    tmp = ((horizontalCuts[j] - horizontalCuts[j - 1]) * (w - verticalCuts[i - 1])) % mod;
                }
                else if (i == 0)
                {
                    tmp = ((horizontalCuts[j] - horizontalCuts[j - 1]) * verticalCuts[0]) % mod;
                }
                else
                {
                    tmp = ((horizontalCuts[j] - horizontalCuts[j - 1]) * (verticalCuts[i] - verticalCuts[i - 1])) % mod;
                }
                max_brock = max(tmp, max_brock);
            }
        }

        max_brock = max(max_brock, ((h - horizontalCuts[h_nums - 1]) * verticalCuts[0]) % mod);
        for (int i = 1; i <= verticalCuts.size(); i++)
        {
            int tmp = 0;
            if (i == v_nums)
            {
                tmp = ((h - horizontalCuts[h_nums - 1]) * (w - verticalCuts[i - 1])) % mod;
            }
            else
            {
                tmp = ((h - horizontalCuts[h_nums - 1]) * (verticalCuts[i] - verticalCuts[i - 1])) % mod;
            }
            max_brock = max(tmp, max_brock);
        }

        return max_brock;
    }
};


class Solution {
    const int mod = 1e9 + 7;
public:
    int maxArea(int h, int w, vector<int>& horizontalCuts, vector<int>& verticalCuts) {
        sort(horizontalCuts.begin(), horizontalCuts.end());
        sort(verticalCuts.begin(), verticalCuts.end());

        return (long long)get_max(h, horizontalCuts) * (long long)get_max(w, verticalCuts) % mod;
    }

    long long get_max(int num, const vector<int>& cuts)
    {
        int n = cuts.size();

        int ret = cuts[0];
        for (int i = 1; i < n; i++)
        {
            ret = max(ret, cuts[i] - cuts[i - 1]);
        }
        ret = max(ret, num - cuts[n - 1]);

        return ret;
    }
};

//int main()
//{
//    vector<int> h({ 1, 2, 4 });
//    vector<int> w({ 1,3 });
//    cout << Solution1().maxArea(5, 4, h, w) << endl;
//
//    return 0;
//}

///////////////////////////////////

class Solution2 {
    vector<vector<int>> ans;
    vector<int> path;
public:
    vector<vector<int>> subsets(vector<int>& nums) {
        ans.push_back(path);
        dfs(nums, 0);

        return ans;
    }

    void dfs(const vector<int>& nums, int pos)
    {
        if (pos == nums.size())
        {
            return;
        }

        for (int i = pos; i < nums.size(); i++)
        {
            path.push_back(nums[i]);
            ans.push_back(path);
            dfs(nums, i + 1);
            path.pop_back();;
        }
    }
};